package cn.jly.flink.wordcount;

import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;

/**
 * line -> (word, 1)
 *
 * @author lanyangji
 */
public class LineToWordAndCount implements FlatMapFunction<String, Tuple2<String, Integer>> {
    @Override
    public void flatMap(String s, Collector<Tuple2<String, Integer>> collector) throws Exception {
        for (String word : s.split("\\W+")) {
            if (StringUtils.isNoneBlank(word)) {
                collector.collect(Tuple2.of(word, 1));
            }
        }
    }
}
